{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys   ###dpmcl（上の3つのセル）\n",
    "sys.path.append('../scripts/')\n",
    "from dp_policy_agent import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trial(animation):  ###qmdp1exec\n",
    "    time_interval = 0.1\n",
    "    world = PuddleWorld(30, time_interval, debug=not animation) \n",
    "\n",
    "    ##ランドマークの追加（意地悪な位置に）##\n",
    "    m = Map()\n",
    "    for ln in [(1,4), (4,1), (-4,-4)]: m.append_landmark(Landmark(*ln))\n",
    "    world.append(m) \n",
    "    \n",
    "    ##ゴール・水たまりの追加（これは特に変更なし）##\n",
    "    goal = Goal(-3,-3)\n",
    "    puddles = [Puddle((-2, 0), (0, 2), 0.1), Puddle((-0.5, -2), (2.5, 1), 0.1)] \n",
    "    world.append(goal)\n",
    "    world.append(puddles[0]) \n",
    "    world.append(puddles[1])\n",
    "    \n",
    "    ##ロボットを作る##\n",
    "    init_pose = np.array([2.5, 2.5, 0]).T\n",
    "    pf = Mcl(m, init_pose, 100)\n",
    "    a = DpPolicyAgent(time_interval, pf, goal)\n",
    "    r = Robot(init_pose, sensor=Camera(m), agent=a, color=\"red\")\n",
    "    world.append(r)\n",
    "        \n",
    "    world.draw()\n",
    "    \n",
    "    return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.7/site-packages/matplotlib/pyplot.py:514: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
      "  max_open_warning, RuntimeWarning)\n"
     ]
    }
   ],
   "source": [
    "def evaluation():\n",
    "    with open(\"ml_result.txt\", \"w\") as f:\n",
    "        num = 1000\n",
    "        for i in range(num):\n",
    "            a = trial(False)\n",
    "            f.write(\"{} {}\\n\".format(a.total_reward+a.final_value, a.in_goal))\n",
    "            f.flush()\n",
    "            \n",
    "evaluation()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
